import 'package:dio/dio.dart';
import 'package:tencent_cloud_chat_demo/utils/authService.dart';
import 'package:tencent_cloud_chat_demo/utils/request.dart';

class CustomSitckerAPI {
  static Future<List<dynamic>?> getAllSticker() async {
    final usersig = await AuthService.getAuthToken();
    final res = await appRequest(
      path: 'https://yunpengim.daboluo.pro/api/user/emotionList',
      method: 'post',
      data: {
        'usersig': usersig,
      },
    );
    if (res.data?['code'] == 1) {
      return res.data?['data'];
    }
    return null;
  }

  static Future<Map<String, dynamic>?> addSticker(
    String filePath,
    String fileName,
  ) async {
    final usersig = await AuthService.getAuthToken();
    FormData formData = FormData.fromMap({
      "usersig": usersig,
      "file": await MultipartFile.fromFile(
        filePath,
        filename: fileName,
      ),
      // 其他字段
      "userId": "12345",
    });
    final res = await appRequest(
      method: 'post',
      path: 'https://yunpengim.daboluo.pro/api/user/customemotion',
      data: formData,
      contentType: 'multipart/form-data',
    );

    if (res.data?['code'] == 1) {
      return res.data?['data'];
    }

    return null;
  }

  static Future<void> deleteSticker(String ids) async {
    final usersig = await AuthService.getAuthToken();
    final res = await appRequest(
      path: 'https://yunpengim.daboluo.pro/api/user/deleteEmotion',
      method: 'post',
      data: {'usersig': usersig, 'emotion_id': ids},
    );
    if (res.data?['code'] == 1) {
      return res.data?['data'];
    }
    return;
  }
}
